#!/bin/bash
#
#  Rewrite src/jbxml to lxl/src/jbxml from java to lxl
#  collections.
#
if [ -d src/jbxml ]&&[ -d lxl/src/jbxml ]
then

    for srcf in $(find src/jbxml -type f -name '*.java')
    do
	tgtf=$(echo "${srcf}" | sed "s%src%lxl/src%")
	#
	tgtd=$(dirname "${tgtf}")
	if [ ! -d "${tgtd}" ]
	then
	    if ! mkdir -p "${tgtd}"
	    then
		cat<<EOF>&2
$0: Error creating target directory '${tgtd}'.
EOF
		exit 1
	    fi
	fi
        #
	if cat "${srcf}" | sed -f copy-lxl-src.sed > "${tgtf}"
	then
	    touch -r "${srcf}" "${tgtf}"
	    ls -l "${tgtf}"
	else
	    cat<<EOF>&2
$0: Error in 'cat ${srcf} | sed -f copy-lxl-src.sed > ${tgtf}'.
EOF
	    exit 1
	fi
    done
    exit 0
else
    cat <<EOF>&2
$0: Error, directory not found 'src/jbxml' or 'lxl/src/jbxml'.
EOF
    exit 1
fi
